import axios from 'axios'
import store from '@/store'

/** 导出excel */
export function exportXls(params, url, file_name) {
  const new_headers = {
    'Authorization': 'bearer ' + store.getters.token
  }
  axios({
      url: url,
      method: 'get',
      headers: new_headers,
      params: params,
      responseType: 'blob'
    })
    .then(res => {
      const url = window.URL.createObjectURL(new Blob([res.data]))
      const link = document.createElement('a')
      link.href = url
      link.setAttribute('download', file_name)
      document.body.appendChild(link)
      link.click()
    }).catch(res => {
      alert(res)
    })
}


// 导出
export function downFiles(blob, fileName) {
  const url = window.URL.createObjectURL(new Blob([blob]))
  const link = document.createElement('a')
  link.href = url
  link.setAttribute('download', `${fileName}.xlsx`)
  document.body.appendChild(link)
  link.click()

  link.remove()
  window.URL.revokeObjectURL(link.href)
}
